package com.neu.servlet.snn;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.snn.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "UpdateAddressServlet", urlPatterns = {"/UpdateAddressServlet.do"})
public class UpdateAddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String a_id = request.getParameter("a_id");
        String a_add = request.getParameter("a_addd");
        String a_name = request.getParameter("a_namee");
        String a_tel = request.getParameter("a_tell");
        UserService userService = new UserService();
        boolean flag = userService.updateAddress(a_name,a_add,a_tel,a_id);
        Map<String, Object> map = new HashMap<>();
            if (flag) {
                map.put("msg", "保存成功");
                String json = JSONObject.toJSONString(map);
                System.out.println(json);
                PrintWriter out = response.getWriter();
                out.print(json);
                out.close();
            }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
